package com.student.bean;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class StudentMenu {
    public static void menu() throws IOException {
        Scanner sc = new Scanner(System.in);
        LogInStudent logInStudent = new LogInStudent();
        OperateStudent operateStudent = new OperateStudent();
        File file = new File("file\\Account.txt");
        // 是否存在储存登录信息的文件，存在登录，否则注册。
        if (file.exists()) {
            System.out.println("登录管理账号");
            logInStudent.login();
        } else {
            System.out.println("注册管理帐号");
            logInStudent.enroll();
        }
        // 加载文件中的学生信息
        if (FileUtils.sizeOf(new File("file\\Student.txt")) > 0) {
            operateStudent.fileIO();
        }
        while (true) {
            System.out.println("---------------空花学生管理系统---------------");
            System.out.println("1.添加学生");
            System.out.println("2.删除学生");
            System.out.println("3.修改学生");
            System.out.println("4.查询学生");
            System.out.println("5.退出");
            System.out.println("请输入您的选择");
            String choose = sc.next();
            switch (choose) {
                case "1":
                    System.out.println("添加学生");
                    operateStudent.addStudent();
                    break;
                case "2":
                    System.out.println("删除学生");
                    operateStudent.deleteStudent();
                    break;
                case "3":
                    System.out.println("修改学生");
                    operateStudent.setStudent();
                    break;
                case "4":
                    System.out.println("查询学生");
                    operateStudent.inquireStudent();
                    break;
                case "5": {
                    System.out.println("退出");
                    System.exit(0);
                    break;
                }
                default:
                    System.out.println("没有这个选项");
                    break;
            }
        }
    }

}
